﻿using UnityEngine;

namespace Core
{
    public abstract class AbstractGameContext : AbstractContext
    {
        // ReSharper disable once InconsistentNaming
        public GameObject gameObject { get; protected set; }
        // ReSharper disable once InconsistentNaming
        public MonoBehaviour mono { get; protected set; }

        public ComponentSystem Factory { get; protected set; }
        public EventSystem Evt { get; protected set; }

        public MemCacheSystem MemCache { get; protected set; }

        public UISystem UI { get; protected set; }
        public ResSystem Res { get; protected set; }
        public ISceneSystem Scene { get; protected set; }
        public TableSystem Table { get; protected set; }
        public AudioSystem Audio { get; protected set; }

        protected T Acquire<T>() where T : Component
        {
            var component = ReferencePool.Acquire<T>();

            component.InstanceId = Utils.ID.Get();
            component.SetSG(Context.Sys, this);

            return component;
        }

        public virtual void AddCoreComponent()
        {
            Factory = Acquire<ComponentSystem>();
            Factory.Awake();

            Evt = Acquire<EventSystem>();
            Evt.Awake();

            Bind = Acquire<Binder>();
            Bind.Awake();

            Reflect = Acquire<Reflector>();
            Reflect.Awake();

            MemCache = Acquire<MemCacheSystem>();
            MemCache.Awake();
        }
    }
}
